package com.cloudkinto.service.system.impl;

import com.cloudkinto.common.RedisKeyConstants;
import com.cloudkinto.service.system.SystemSetService;
import com.cloudkinto.vo.system.OmsSystemEntity;
import com.cloudkinto.vo.system.omp.OmpSystemEntity;
import com.cloudkinto.vo.system.wms.WmsSystemEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SystemSetServiceImp implements SystemSetService {

    private final RedisTemplate redisTemplate;

    @Override
    public void ompSet(OmpSystemEntity req, Long tenantId) {
        redisTemplate.opsForValue().set(RedisKeyConstants.Omp_System_Set + tenantId, req);
    }


    @Override
    public OmpSystemEntity getOmpSet(Long tenantId) {
        Object omp = redisTemplate.opsForValue().get(RedisKeyConstants.Omp_System_Set + tenantId);
        if (omp == null) {
            return new OmpSystemEntity();
        } else {
            return (OmpSystemEntity) omp;
        }
    }

    @Override
    public WmsSystemEntity getWmsSet(Long storageId) {
        Object wms = redisTemplate.opsForValue().get(RedisKeyConstants.Wms_System_Set + storageId);
        if (wms == null) {
            return new WmsSystemEntity();
        } else {
            return (WmsSystemEntity) wms;
        }
    }


    @Override
    public void wmsSet(WmsSystemEntity req, Long storageId) {
        redisTemplate.opsForValue().set(RedisKeyConstants.Wms_System_Set + storageId, req);
    }







    @Override
    public OmsSystemEntity getOmsSet(Long companyId) {
        if (companyId == null) return null;
        Object wms = redisTemplate.opsForValue().get(RedisKeyConstants.Oms_System_Set + companyId);
        if (wms == null) {
            return new OmsSystemEntity();
        } else {
            return (OmsSystemEntity) wms;
        }
    }


    @Override
    public void omsSet(OmsSystemEntity req, Long companyId) {
        if (companyId == null) return;
        redisTemplate.opsForValue().set(RedisKeyConstants.Oms_System_Set + companyId, req);
    }


}
